package ar.edu.utn.frsf.tpae.a2014.g03.persistence.dao.impl;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import ar.edu.utn.frsf.tpae.a2014.g03.persistence.dao.TransportistaDAO;
import ar.edu.utn.frsf.tpae.a2014.g03.persistence.model.Transportista;

@Repository
public class TransportistaHibernateDao implements TransportistaDAO {

	private SessionFactory sessionFactory;

	// Setter utilizado por Spring.
	@Autowired
	public void setSessionFactory(SessionFactory factory) {
		this.sessionFactory = factory;
	}

	private Session getCurrentSession() {
		return sessionFactory.getCurrentSession();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Transportista> findAll() {
		return getCurrentSession().createCriteria(Transportista.class).list();
	}

}
